﻿using com.iot.core.data.entity;

using System.Linq.Dynamic.Core; 
using Microsoft.EntityFrameworkCore;

namespace com.iot.core.data.service
{
    public class HtRoleMenuService : BaseService<HtRoleMenu>, IHtRoleMenuService
    {
        public async Task<List<string>> GetRolesUrlsAsync(List<long> lrids)
        {
            var DB = BaseMapper.DB;
            var l =await DB.Set<HtRoleMenu>()
                .Where(a => lrids.Contains(a.HtroleId))
              .Join(
                    DB.Set<HtMenu>(),
                    a => new { HtmenuId = a.HtmenuId, BDeleted = false },
                    b => new { HtmenuId = b.Id, BDeleted = b.Deleted },
                    (a, b) => new { HtpageId = b.HtpageId }
                    )
              .Join(
                    DB.Set<HtPage>(),
                    a => new { HtpageId = a.HtpageId, BDeleted = false },
                    b => new { HtpageId = b.Id, BDeleted = b.Deleted },
                    (a, b) => new { HtpageId = b.Id }
                )
              .Join(
                DB.Set<HtPageAuth>(),
                    a => new { HtpageId = a.HtpageId, BDeleted = false },
                    b => new { HtpageId = b.HtpageId, BDeleted = b.Deleted },
                    (a, b) => b.Urls
                )
              .ToListAsync();
            return l;
        }

        public async Task<List<long>> GetRolesMenuIdsAsync(List<long> lrids)
        {
            var DB = BaseMapper.DB;
            var l = await DB.Set<HtRoleMenu>()
                .Where(a => lrids.Contains(a.HtroleId))
                .Select(a => a.HtmenuId)
                .ToListAsync();
            return l; 
        }


    }
}
